/*
* Udp_Server.h
* Last edited: 27.08.2014
* Author: David Noack
*/

#ifndef UDP_SERVER_H_
#define UDP_SERVER_H_

#include "Com_Interface.h"
#include "MyThreadClass.h"

#define UDP_LOG "Log_Udp"


/**
\class Udp_Server
\brief Implements a udp-server for prngd.
*/
class Udp_Server : public Com_Interface, MyThreadClass{

	public:

	/** Constructor */
	Udp_Server(Prngd_State state);

	/**Destructor */
	~Udp_Server()
	{
		if(prngd != NULL)
			delete prngd;
		if(create_socket != 0)
			close(create_socket);
	};


	private:

		/** Unix Socket for the udp connection*/
		int create_socket;
		/** Var for the address length of the server address.*/
		socklen_t addrlen;
		/** Var for the address length of the client address.*/
		socklen_t client_addr_len;
		/** Var for the number of received bytes from the socket.*/
		ssize_t size;
		/** Struct for the address of the server.*/
		struct sockaddr_in address;
		/** Struct for the address of the client.*/
		struct sockaddr_in client_addr;
		struct sockaddr_in temp_addr;

		/** See doc for My_ThreadClass.*/
		virtual void thread_listen(pthread_t parent_th);
		/** See doc for My_ThreadClass.*/
		virtual void thread_work();

};





#endif /* UDP_SERVER_H_ */
